//        System.out.println(content);
//        System.out.println("fff<div id=\"m_blog\" class=\"modbox\" style=\"overflow-x:hidden;\">".matches("[^<>]*<div[^>]+id[^>=]*=[^=>]*m_blog[^=>]*[^>]*>[^<>]*"));
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Scanner;

/**
 *
 * @author xddai
 */
public class BaiduBlog {

    public static void main(String[] args) throws IOException {
        String address = "http://hi.baidu.com/yingnet/blog/item/78786e31c618f912eac4af71.html";
        String content = getContent(address);
        System.out.println(getDiv(content));
    }

    public static String getContent(String address) throws IOException {
        URL url = new URL(address);
        StringBuilder sb = new StringBuilder();
        InputStreamReader ins = new InputStreamReader(new FileInputStream("c:/tt.html"), "gbk");
        BufferedReader br = new BufferedReader(ins);
        String demp;
        while ((demp = br.readLine()) != null) {
            sb.append(demp);
            sb.append('\n');
        }
        br.close();
        return sb.toString();
    }

    public static String getDiv(String content) {
        StringBuilder sb = new StringBuilder();
        Scanner sc = new Scanner(content);
        String demp = "";
        while (sc.hasNextLine()) {
            demp = sc.nextLine();
            if (demp.matches("[^<>]*<div[^>]+id[^>=]*=[^=>]*m_blog[^=>]*[^>]*>[^<>]*")) {
                break;
            }
        }
        sb.append(demp+"\n");
        int i = 1;
        while (i > 0 && sc.hasNextLine()) {
            demp = sc.nextLine();
            if (demp.matches("[^<>]*<div[^/>]+>[^<>]*")) {
                i++;
            }
            if (demp.matches("[^<>]*</s*div\\s*>[^<>]*")) {
                i--;
            }
            sb.append(demp+"\n");
        }
        sc.close();
        return sb.toString();
    }
}
